package com.app.view.pulltorefresh;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
 * Created by Administrator on 2016/11/24.
 */

public class PullableRecyclerView extends RecyclerView implements Pullable {


    public PullableRecyclerView(Context context) {
        super(context);
    }

    public PullableRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PullableRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean canPullDown() {
        if (this.getAdapter().getItemCount() == 0) {
            // 没有item的时候也可以下拉刷新
            return true;
        } else if (!canScrollVertically(-1)) {
            // 滑到RecyclerView的顶部了
            return true;
        }
        return false;
    }


    @Override
    public boolean canPullUp() {
        if (this.getAdapter().getItemCount() == 0) {
            // 没有item的时候也可以上拉加载
            return true;
        } else if (!canScrollVertically(1)) {
            return true;
        }
        return false;
    }
}
